Skip to content

packaging, solver: compatible_version=true for mainnet; warn when a replayed contract state is lost - #83

Merged
EnzinoBB merged 1 commit into
masterfrom
fix/compatible-version-replay
Oct 23, 2026
Merged

EnzinoBB merged 1 commit into
masterfrom
fix/compatible-version-replay

Conversation

@EnzinoBB

Copy link
Copy Markdown
Collaborator

A mainnet node syncing with the packaged config.ini stopped for good at a valid block: its own balance check rejected the block's only transaction, because its balance for the sender was one fee lower than the network's.

Cause (official behaviour). While syncing, the node re-executes contract calls to recover their states. A dice-game contract computes the attached amount from its own balance, which during the replay is already the balance after the block's payout. The re-execution of a winning call fails, the contract's cached state stays out of date, and the fee of a later payout of the contract is charged to an earlier caller (smartSourceTransactionReleased uses the contract's last known starter). Mainnet nodes disagree among themselves on such wallets by exactly these fees. Other wallets are not affected: 80 random wallets matched the public explorer.

Changes

  • packaging/mainnet/config.ini: compatible_version=true, which is the node binary's default (the official file sets false). A block that fails the node's own transaction check is logged (skip block validation) and stored instead of stopping the node. Validation as a trusted node is unchanged.
  • SmartContracts::get_actual_state: a warning when a block declares a new state that the node cannot obtain, and a replayed state with a wrong hash is now a warning instead of a debug line, so the divergence shows in the logs.
  • docs: differences.md (packaged config, contract replay) and CHANGES.md.

The fee attribution itself is unchanged. Changing it would change balances compared with official nodes; that is left for a separate discussion.

🤖 Generated with Claude Code

…eplayed contract state is lost

Replaying some contracts while syncing is not reproducible (official
behaviour): a game contract that reads its own balance sees it after the
block's payout, the re-execution fails, the contract state stays out of
date and a later payout's fee can be charged to an earlier caller. A
syncing node then disagrees with the network on that caller's balance by
a fee, and with compatible_version=false (the official config.ini) stops
for good at the first block whose transaction those balances reject.
The packaged config now uses the binary's default, true, which logs and
stores such a block. get_actual_state warns when a state the block
declares is not available, and a replayed state with a wrong hash is a
warning instead of a debug line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EnzinoBB
EnzinoBB merged commit 975ae01 into master Oct 23, 2026
5 checks passed
EnzinoBB added a commit that referenced this pull request Nov 1, 2026
…inst the chain

A node that replays contract calls while syncing cannot reproduce every execution (a contract
whose result depends on its own balance, for instance). Such a contract's state stays stale, the
node never obtains the state the chain declares, and its later executions start from a wrong
state. This change lets the node notice and repair that.

- each contract's StateItem records the call and the hash of the last new_state with a state
  (declared_ref, declared_hash), whether or not the node obtained the state, so a node knows which
  contracts it holds stale (is_stale, count_stale). The declaration is serialized after the
  existing fields only when one is known: an item of an earlier checkpoint keeps its bytes and its
  hash; the quick-start validation fills it from the chain when the block is stored
- once the node is live (the first live block after read ones), every stale contract is asked for
  from the confidants with the existing StateRequest (StateFetcher, solver/statefetcher.hpp): at most
  16 a round, oldest first, each again after 50, 100, ... up to 5000 rounds
- a StateReply is taken only for a contract this node asked for, and only for the declared call
  with the declared hash (newer, older or other states are ignored); the cache is overwritten (a
  re-execution may have stored a wrong state for the same call). A contract without a declaration
  is checked against its block as before, but no longer taken unverified when the block is not
  stored; a state of an unknown contract is refused
- removing a block moves the declaration back to the latest successful new_state left on the chain
- get_actual_state warns when a state the block declares is not available
- [params] sync_contract_execution (default true, the current behaviour): false skips the
  re-execution of contract calls while the node reads the blockchain; every state is then fetched
  from the confidants once the node is live, and syncing needs no executor
- unit tests in tests/csnode/smartcontracts_tests.cpp (state bookkeeping, earlier layout, the reply
  check)

Local: the request and reply messages are the existing ones, and a node only changes what it
accepts. It builds on the PR that charges emitted transactions to the latest execution (fee rule).

Same change in the community fork: #95, #96 (and the warning of #83).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant